var app = getApp();

Page({
    data: {
        luntext: [ "全部", "进行中", "已结束", "违规" ],
        activeIndex: 0,
        page: 1,
        my_activity: []
    },
    onLoad: function(t) {
        wx.hideShareMenu();
        var a = wx.getStorageSync("db_tab"), i = app.contains(a, "../myactive/myactive");
        console.log(i), 0 != i && (a[i].color = "selsects", a[i].img = a[i].icon1, console.log(a)), 
        this.setData({
            yes: i,
            db_tab: a
        }), this.refresh();
    },
    refresh: function(t) {
        var i = this, a = wx.getStorageSync("userInfo").id, e = app.today_time(), n = wx.getStorageSync("url"), s = i.data.my_activity, c = i.data.page;
        app.util.request({
            url: "entry/wxapp/MyActivity",
            data: {
                user_id: a,
                page: c
            },
            success: function(t) {
                if (console.log(t), 0 < t.data.length) {
                    for (var a in s = s.concat(t.data), t.data) t.data[a].end_time = app.ormatDate(t.data[a].end_time).slice(0, 16), 
                    t.data[a].start_time = app.ormatDate(t.data[a].start_time).slice(0, 16), 1 == t.data[a].is_close ? e >= t.data[a].end_time ? (t.data[a].sign_up = "已结束", 
                    t.data[a].sign_state = "sign_over") : (e >= t.data[a].start_time ? t.data[a].sign_up = "进行中" : t.data[a].sign_up = "报名中", 
                    t.data[a].sign_state = "sign_up") : (t.data[a].sign_up = "已结束", t.data[a].sign_state = "sign_over");
                    i.setData({
                        page: c + 1,
                        my_activity: s,
                        my_activitys: s
                    });
                } else i.setData({
                    my_activity: s,
                    my_activitys: s
                });
                i.setData({
                    url: n
                });
            }
        });
    },
    tabClick: function(t) {
        var a = this, i = t.currentTarget.id, e = a.data.my_activitys, n = app.today();
        if (0 == i) a.setData({
            my_activity: a.data.my_activitys
        }); else if (1 == i) {
            var s = [];
            for (var c in e) n > e[c].start_time && s.push(e[c]);
            a.setData({
                my_activity: s
            });
        } else if (2 == i) {
            s = [];
            for (var r in e) n > e[r].end_time && s.push(e[r]);
            a.setData({
                my_activity: s
            });
        } else if (3 == i) {
            s = [];
            for (var o in e) 3 == e[o].status && s.push(e[o]);
            a.setData({
                my_activity: s
            });
        }
        a.setData({
            sliderOffset: t.currentTarget.offsetLeft,
            activeIndex: t.currentTarget.id
        });
    },
    my_activity: function(t) {
        console.log(t);
        var a = t.currentTarget.dataset.id, i = this.data.my_activity;
        for (var e in i) if (a == i[e].id) var n = i[e];
        wx.navigateTo({
            url: "../activemanage/activemanage?id=" + a + "&activity_type=" + n.activity_type + "&end_time=" + n.end_time + "&sign_up=" + n.sign_up + "&total_ticket=" + n.total_ticket + "&gz_num=" + n.gz_num + "&title=" + n.title + "&logo=" + n.logo + "&url=" + this.data.url + "&is_close=" + n.is_close + "&hx_code=" + n.hx_code + "&zd_money=" + n.zd_money
        });
    },
    wode: function() {
        var t = this.data.db_tab;
        wx.reLaunch({
            url: t[3].src
        });
    },
    fabu: function() {
        wx.reLaunch({
            url: "../fabu/fabu"
        });
    },
    index: function() {
        var t = this.data.db_tab;
        wx.reLaunch({
            url: t[0].src
        });
    },
    classifination: function(t) {
        var a = this.data.db_tab;
        wx.reLaunch({
            url: a[1].src
        });
    },
    mine_activity: function(t) {
        var a = this.data.db_tab;
        wx.reLaunch({
            url: a[2].src
        });
    },
    onReady: function() {},
    onShow: function() {
        this.setData({
            page: 1,
            my_activity: []
        }), this.refresh();
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {
        this.setData({
            my_activity: [],
            page: 1,
            activeIndex: 0
        }), this.refresh(), wx.stopPullDownRefresh();
    },
    onReachBottom: function() {
        this.refresh();
    }
});